import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import axios from 'axios'
import './assets/css/global.css'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from './store/index'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import common from '@/lib/common'
Vue.use(ElementUI)
Vue.prototype.common = common


Vue.prototype.$global_limit = 10
Vue.prototype.$global_page = 1
// Vue.prototype.$action_url = 'http://xgjd_project.test/'
// Vue.prototype.$excel_url = 'http://xgjd_project.test/admin/import_excel'
// axios.defaults.baseURL = 'http://xgjd_project.test/'

Vue.prototype.$action_url = 'https://xgjd.luduanzhang.cn/'
Vue.prototype.$excel_url = 'https://xgjd.luduanzhang.cn/admin/import_excel'
axios.defaults.baseURL = 'https://xgjd.luduanzhang.cn/'
axios.interceptors.request.use(config => {
    NProgress.start()
    config.headers.Authorization = window.sessionStorage.getItem('token')
    return config
})
axios.interceptors.response.use(config => {
        NProgress.done()
        // if (config.data.code === 1003) {
        // }
        return config
        // if (config.data.code !== 200) {
        //   window.sessionStorage.clear();
        //   var vm = new Vue()
        // //   vm.$message.error("Token失效,请重新登录")
        //   setTimeout(function () {
        //     return router.push('/login');
        //   }, 1000);
        // } else {
        //   return config;
        // }
    }
)
Vue.prototype.$http = axios
Vue.config.productionTip = false
//验证
Vue.directive('has', {
    inserted: function (el, binding) {
        if (!Vue.prototype.$is_has(binding.value)) {
            el.parentNode.removeChild(el)
        }
    }
})

Vue.prototype.$is_has = function (value) {
    let isExist = false
    let role = store.state.userInfo.url
    let role_arr = role.split(',')
    if (role_arr.includes(value)) {
        isExist = true
    }
    return isExist
}

new Vue({
    store,
    router,
    render: h => h(App),
}).$mount('#app')
